import time
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from common.Utils import ForumDriver

class ForumPrinfo:
    driver = ""
    def __init__(self):
        self.driver = ForumDriver.driver

    def PInfoPageelements(self):
        #在论坛贴子详情页的基础上，点击私信
        self.driver.find_element(By.CSS_SELECTOR,"#btn_details_send_message").click()
        #检查擦除按钮
        self.driver.find_element(By.CSS_SELECTOR,"#index_message_modal > div > div > div.modal-header > button")
        #检查收到私信人的名字
        self.driver.find_element(By.CSS_SELECTOR,"#index_message_receive_user_name > strong")
        #检查发送私信输入框
        self.driver.find_element(By.CSS_SELECTOR,"#index_message_receive_content")
        #检查取消按钮
        self.driver.find_element(By.CSS_SELECTOR,"#index_message_receive_cancel")
        #检查发送按钮
        self.driver.find_element(By.CSS_SELECTOR,"#btn_index_send_message")

    def PInfofunPageFunctions(self):
        #先看一下私信输入框为空的时候，能否发送成功
        #点击私信按钮
        self.driver.find_element(By.CSS_SELECTOR, "#btn_details_send_message").click()
        input_element = self.driver.find_element(By.CSS_SELECTOR,"#index_message_receive_content")
        action = ActionChains(self.driver)
        time.sleep(2)
        #找到发送按钮
        time.sleep(1)
        self.driver.find_element(By.CSS_SELECTOR,"#btn_index_send_message").click()
        time.sleep(1)
        #理论会出现警告，检查一下警告出现没
        self.driver.find_element(By.CSS_SELECTOR,"body > div.jq-toast-wrap.bottom-right > div")
        print("出现警告请输入要发送的内容")
        ForumDriver.GetScreeShot()


        #先看一下私信输入框不为空的时候，能否发送成功
        self.driver.find_element(By.CSS_SELECTOR, "#btn_details_send_message").click()
        input_element = self.driver.find_element(By.CSS_SELECTOR, "#index_message_receive_content")
        action = ActionChains(self.driver)
        time.sleep(2)
        action.click(input_element).send_keys("hello").send_keys(Keys.RETURN).perform()
        # 找到发送按钮
        time.sleep(1)
        self.driver.find_element(By.CSS_SELECTOR, "#btn_index_send_message").click()
        time.sleep(1)
        # 理论会出现警告，检查一下警告出现没
        self.driver.find_element(By.CSS_SELECTOR, "body > div.jq-toast-wrap.bottom-right > div")
        print("出现警告请输入要发送的内容")
        ForumDriver.GetScreeShot()
        text = self.driver.find_element(By.CSS_SELECTOR, "body > div.jq-toast-wrap.bottom-right > div").text
        print("text")
        ForumDriver.GetScreeShot()





